package com.reverie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.reverie.common.pojo.CommonPageReq;
import com.reverie.common.pojo.CommonResult;
import com.reverie.dto.req.ShopperQueryParam;
import com.reverie.entity.Shopper;
import com.reverie.service.IShopperService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("shopper")
public class ShopperController {

    @Resource
    private IShopperService shopperService;

    @PostMapping("queryPage")
    public CommonResult<Page<Shopper>> queryPage(@RequestBody CommonPageReq<ShopperQueryParam> queryPageParam){
        return CommonResult.data(shopperService.queryPage(queryPageParam));
    }

    @PostMapping("save")
    public CommonResult<Boolean> onSave(@RequestBody Shopper shopper){
        return CommonResult.data(shopperService.saveOrUpdate(shopper));
    }

    @PostMapping("delete")
    public CommonResult<Boolean> delete(@RequestBody Shopper shopper){
        return CommonResult.data(shopperService.removeById(shopper.getId()));
    }

}
